<script type="text/javascript">
$(document).ready(function(){
	  $('#ItemCategoryId').live('change', function() {
	    if($(this).val().length != 0) {
		    console.log("categoryId: " + $(this).val())
	      $.getJSON('/asset/items/get_models_ajax',
	                  {catId: $(this).val()},
	                  function(types) {
	                    if(types !== null) {
	                      populateList(types);
	                    }
	        });
	      }
	    });
	});
	 
	function populateList(types) {
	  var options = '';
	 
	  $.each(types, function(index, type) {
	    options += '<option value="' + index + '">' + type.toUpperCase() + '</option>';
	  });
	  $('#ItemTypeId').html(options);
	  $('#types').show();
	 
	}
	$(function() {
		$( "#OwnershipDate" ).datepicker();
	});
	$(document).ready(function(){
		<!--
		var currentTime = new Date()
		var month = currentTime.getMonth() + 1
		var day = currentTime.getDate()
		var year = currentTime.getFullYear()
		$( "#OwnershipDate" ).val(month + "/" + day + "/" + year)
		//-->
	});
	$(function() {
		$( "#ItemDate" ).datepicker({dateFormat: 'mm/dd/yy'});
	});
	$(document).ready(function(){
		<!--
		
		var currentTime = new Date()
		var month = currentTime.getMonth() + 1
		var day = currentTime.getDate()
		var year = currentTime.getFullYear()
		$( "#ItemDate" ).val(month + "/" + day + "/" + year)
		//-->
	});
</script>
<div class="items form">
	<div class="table">
	<?php echo $this->Form->create('Item',array('enctype' => 'multipart/form-data'));?>
		<table class="listing form" cellpadding="0" cellspacing="0">
			<tr>
				<th class="full" colspan="2"><?php __('Edit Item'); ?></th>
			</tr>
			<?php echo $this->Form->input('id'); ?>
			<tr class="bg">
				<td class="first"><strong>Kew.Pa.2</strong></td>
				<td class="last"><?php echo $this->Form->input('q_pa',array('div' => false, 'label'=>''));?>
			</td>
			</tr>
			<tr>
				<td class="first"><strong>Nama</strong></td>
				<td class="last"><?php echo $this->Form->input('name', array('label' => false)); ?>
				</td>
			</tr>
			<tr class="bg">
				<td class="first"><strong>Kod Nasional</strong></td>
				<td class="last"><?php echo $this->Form->input('national_code', array('label' => false)); ?>
				</td>
			</tr>
			<tr>
				<td class="first"><strong>Kategori</strong></td>
				<td class="last"><?php echo $this->Form->input('category_id',array('label' => false, 'div' => false)); ?>
				</td>
			</tr>
			<tr class="bg">
				<td class="first"><strong>Jenis</strong></td>
				<td class="last"><?php echo $this->Form->input('type_id',array('label' => false, 'div' => false)); ?>
				</td>
			</tr>
			<tr>
				<td class="first"><strong>Buatan</strong></td>
				<td class="last"><?php echo $this->Form->input('origin_id',array('label' => false, 'div' => false, 'style' => 'width: 185px')); ?>
				</td>
			</tr>
			<tr class="bg">
				<td class="first"><strong>Pembekal</strong></td>
				<td class="last"><?php echo $this->Form->input('supplier_id',array('label' => false, 'div' => false)); ?>
				</td>
			</tr>
			<tr>
				<td class="first"><strong>Jenis Perolehan</strong></td>
				<td class="last"><?php echo $this->Form->input('ownership_id',array('label'=> false, 'div' => false));?>
				</td>
			</tr>
			<tr class="bg">
				<td class="first"><strong>Tarikh Perolehan</strong></td>
				<td class="last"><input type="text" name="data[Item][ownership_date]"
					id="OwnershipDate">
				</td>
			</tr>
			<tr>
				<td class="first"><strong>No Siri</strong></td>
				<td class="last"><?php echo $this->Form->input('manufacturer_serial_no', array('label' => false)); ?>
				</td>
			</tr>
			<tr class="bg">
				<td class="first"><strong>Harga Perolehan</strong></td>
				<td class="last"><?php echo $this->Form->input('price', array('label' => false)); ?>
				</td>
			</tr>
			<tr>
				<td class="first"><strong>Tarikh Diterima</strong></td>
				<td class="last"><input type="text" name="data[Item][received_date]" id="ItemDate">
				</td>
			</tr>
			<tr class="bg">
				<td class="first"><strong>Tempoh Jaminan</strong></td>
				<td class="last"><input name="data[Item][warranty_period][period]"
					type="text" value="" id="ItemWarrantyPeriod"> <select
					name="data[Item][warranty_period][type]"
					id="ItemWarrantyPeriod[type]">
						<option value="0">day</option>
						<option value="1">month</option>
						<option value="2">year</option>
				</select></td>
			</tr>
			<tr>
				<td class="first"><label for="FileImage"><strong>Image </strong>
				</label>
				</td>
				<td class="last"><input type="file" name="data[File][image]"
					id="FileImage" /></td>
			</tr>
			<tr class="bg">
				<td class="first"><strong>Catatan</strong></td>
				<td class="last"><?php echo $this->Form->input('remarks', array('label' => false)); ?>
				</td>
			</tr>
		</table>
	<?php echo $this->Form->end(__('Simpan', true));?>
	
	<?php /*
	$filename = $item['Item']['received_date'];
if (file_exists($filename)) {
    echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}?>
	<?php
$before = $item['Item']['received_date'];
echo "Before is ".date("Y/m/d", $before);
*/?>
</div>
</div>
